﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace NeedForSmash
{
    public class Camera
    {
        private Vector3 _position;
        private Vector3 _lookAt;
        private Matrix _viewMatrix;
        private Matrix _projectionMatrix;
        private float _aspectRatio;
        public float _cameraYaw = 0;
        private Vector3 cameraReference = new Vector3(0, 0, 1);

        public Camera(Viewport viewport)
        {
            this._aspectRatio = ((float)viewport.Width) / ((float)viewport.Height);
            this._projectionMatrix = Matrix.CreatePerspectiveFieldOfView(
                                        MathHelper.ToRadians(40.0f),
                                        this._aspectRatio,
                                        1.0f,
                                        10000.0f);
        }

        public Vector3 Position
        {
            get { return this._position; }
            set { this._position = value; }
        }
        public Vector3 LookAt
        {
            get { return this._lookAt; }
            set { this._lookAt = value; }
        }
        public Matrix ViewMatrix
        {
            get { return this._viewMatrix; }
        }
        public Matrix ProjectionMatrix
        {
            get { return this._projectionMatrix; }
        }
        public void Update()
        {
            this._viewMatrix =
                Matrix.CreateLookAt(this._position, this._lookAt, Vector3.Up);

            /* Matrix rotationMatrix = Matrix.CreateRotationY(_cameraYaw);
            Vector3 transformedReference = Vector3.Transform(cameraReference, rotationMatrix);
            Vector3 cameraLookat = _position + transformedReference;

            _viewMatrix = Matrix.CreateLookAt(_position, cameraLookat, new Vector3(0.0f, 1.0f, 0.0f));
            _projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(40.0f), _aspectRatio, nearClip, farClip); */
        }

        public void MoveLeft()
        {
            
        }

        public void MoveRight()
        {

        }

        public void MoveForward()
        {
            Matrix forwardMovement = Matrix.CreateRotationY(_cameraYaw);
            Vector3 v = new Vector3(0, 0, 1);
            v = Vector3.Transform(v, forwardMovement);
            _position.Z += v.Z;
            _position.X += v.X;
        }

        public void MoveBackward()
        {
            Matrix forwardMovement = Matrix.CreateRotationY(_cameraYaw);
            Vector3 v = new Vector3(0, 0, -1);
            v = Vector3.Transform(v, forwardMovement);
            _position.Z += v.Z;
            _position.X += v.X;
        }
    }
}
